package com.ims.core.bas.controller;

import com.ims.common.annotation.Log;
import com.ims.common.core.controller.BaseController;
import com.ims.common.core.domain.AjaxResult;
import com.ims.common.core.page.TableDataInfo;
import com.ims.common.enums.BusinessType;
import com.ims.common.utils.poi.ExcelUtil;
import com.ims.core.bas.domain.BasCompany;
import com.ims.core.bas.service.IBasCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公司Controller
 *
 * @author IMS
 * @date 2024-03-03
 */
@RestController
@RequestMapping("/core/company")
public class BasCompanyController extends BaseController
{
    @Autowired
    private IBasCompanyService basCompanyService;

    /**
     * 查询公司列表
     */
    @PreAuthorize("@ss.hasPermi('core:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasCompany basCompany)
    {
        startPage();
        List<BasCompany> list = basCompanyService.selectBasCompanyList(basCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司列表
     */
    @PreAuthorize("@ss.hasPermi('core:company:export')")
    @Log(title = "公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasCompany basCompany)
    {
        List<BasCompany> list = basCompanyService.selectBasCompanyList(basCompany);
        ExcelUtil<BasCompany> util = new ExcelUtil<BasCompany>(BasCompany.class);
        util.exportExcel(response, list, "公司数据");
    }

    /**
     * 获取公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('core:company:query')")
    @GetMapping(value = "/{companycode}")
    public AjaxResult getInfo(@PathVariable("companycode") String companycode)
    {
        return success(basCompanyService.selectBasCompanyByCompanycode(companycode));
    }

    /**
     * 新增公司
     */
    @PreAuthorize("@ss.hasPermi('core:company:add')")
    @Log(title = "公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasCompany basCompany)
    {
        return toAjax(basCompanyService.insertBasCompany(basCompany));
    }

    /**
     * 修改公司
     */
    @PreAuthorize("@ss.hasPermi('core:company:edit')")
    @Log(title = "公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasCompany basCompany)
    {
        return toAjax(basCompanyService.updateBasCompany(basCompany));
    }

    /**
     * 删除公司
     */
    @PreAuthorize("@ss.hasPermi('core:company:remove')")
    @Log(title = "公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companycodes}")
    public AjaxResult remove(@PathVariable String[] companycodes)
    {
        return toAjax(basCompanyService.deleteBasCompanyByCompanycodes(companycodes));
    }
}
